home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / vexfind.c < prev    next >
C/C++ Source or Header  |  1994-11-15  |  3KB  |  177 lines

  1. /*
  2.  *                VexFind.c
  3.  *
  4.  * Find the system in VORTEX.SYS.
  5.  */
  6.  
  7. /*
  8.  *                History
  9.  *
  10.  * 90Jul29  HAW Initial creation.
  11.  */
  12.  
  13. /*
  14.  *                Contents
  15.  *
  16.  */
  17.  
  18. #include "ctdl.h"    /* header file  */
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <stdlib.h>
  22. #include <math.h>
  23. #include <ctype.h>
  24. #include <time.h>
  25. #include <proto/exec.h>
  26. #include <dos/dos.h>
  27. #include <pragmas/dos_pragmas.h>
  28. #include "exec/memory.h"
  29. #include "exec/ports.h"
  30. #include "exec/exec.h"
  31.  
  32. #define V_COPYRIGHT "Copyright (c) 1990, 1991 by Hue, Jr."
  33. #define TITLE "VexFind V1.1\n%s\n", V_COPYRIGHT
  34.  
  35. #define USAGE    "Usage: VEXFIND \"<system name>\"\n\n  or\n\nVEXFIND\n"
  36.  
  37. FILE *vx;
  38. void Find(char *name);
  39. void ShowAll(void);
  40. void ShowRoomInfo(int x);
  41.  
  42. extern CONFIG cfg;
  43. extern rTable *roomTab;            /* RAM index of rooms        */
  44. extern aRoom  roomBuf;            /* room buffer            */
  45. extern FILE   *roomfl;            /* file descriptor for rooms    */
  46. extern int    thisRoom;            /* room currently in roomBuf    */
  47.  
  48. char TabRead = FALSE;
  49. /*
  50.  * main()
  51.  *
  52.  * This is the main manager.
  53.  */
  54. int main(int, char **);
  55. int main(argc, argv)
  56. int  argc;
  57. char **argv;
  58. {
  59.     extern char *READ_ANY;
  60.     SYS_FILE filename;
  61.  
  62.     printf(TITLE);
  63.  
  64.     if (argc > 2) {
  65.     printf(USAGE);
  66.     exit(1);
  67.     }
  68.  
  69.     if ((vx = fopen("VORTEX.SYS", READ_ANY)) == NULL) {
  70.     if (!readSysTab(FALSE, TRUE)) {
  71.         printf("Couldn't find anything to work with.\n");
  72.         exit(1);
  73.     }
  74.     TabRead = TRUE;
  75.     makeSysName(filename, "VORTEX.SYS", &cfg.netArea);
  76.     if ((vx = fopen(filename, READ_ANY)) == NULL) {
  77.         printf("Couldn't find a VORTEX.SYS to work with.\n");
  78.         exit(1);
  79.     }
  80.     }
  81.  
  82.     if (argc == 1) ShowAll();
  83.     else Find(argv[1]);
  84. return 0;
  85. }
  86.  
  87. typedef struct {
  88.     label Id, Name;
  89.     char InUse;
  90. } VtRecord;
  91.  
  92. /*
  93.  * ShowAll()
  94.  *
  95.  * This function shows all the systems listed in the vortex list.
  96.  */
  97. void ShowAll()
  98. {
  99.     VtRecord Vtx;
  100.     int i = 0;
  101.  
  102.     while (fread(&Vtx, 1, sizeof Vtx, vx) > 0)
  103.     printf("%3d. %-25s : %s\n", i++, Vtx.Name, Vtx.Id);
  104. }
  105.  
  106. /*
  107.  * Find()
  108.  *
  109.  * This function finds the named system in the vortex list.  First occurrence
  110.  * only.
  111.  */
  112. void Find(char *name)
  113. {
  114.     VtRecord Vtx;
  115.     int i = 0;
  116.  
  117.     if (!TabRead && readSysTab(FALSE, FALSE))    TabRead = TRUE;
  118.  
  119.     while (fread(&Vtx, 1, sizeof Vtx, vx) > 0) {
  120.     if (stricmp(name, Vtx.Name) == 0) {
  121.         printf("%3d. %s\n", i, Vtx.Name);
  122.         ShowRoomInfo(i);
  123.         break;
  124.     }
  125.     i++;
  126.     }
  127. }
  128.  
  129. typedef struct {
  130.     int        vRoomNo;    /* Room we are associated with        */
  131.     AN_UNSIGNED vGen;    /* Allows checking for no longer in use */
  132.     MSG_NUMBER  vHighest;   /* Highest msg # received        */
  133.     long        vLastDate;  /* Date of last message received    */
  134. } VORTEX;
  135.  
  136. /*
  137.  * ShowRoomInfo()
  138.  *
  139.  * This function tries to show which rooms are actually shared.
  140.  */
  141. void ShowRoomInfo(int x)
  142. {
  143.     char temp[10];
  144.     SYS_FILE vortex;
  145.     VORTEX data;
  146.     int room;
  147.     FILE *fd;
  148.  
  149.     if (TabRead) {
  150.     sprintf(temp, "%d.vex", x);
  151.     makeSysName(vortex, temp, &cfg.netArea);
  152.     if ((fd = fopen(vortex, READ_ANY)) != NULL) {
  153.         while (fread(&data, sizeof data, 1, fd) >= 1) {
  154.         room = data.vRoomNo;
  155.         if (roomTab[room].rtflags.INUSE &&
  156.                 roomTab[room].rtgen == data.vGen) {
  157.             printf("%s ", roomTab[room].rtname);
  158.             printf("Last message is %lu, ", data.vHighest);
  159.             printf("Date on last message was %s.\n",
  160.                         LastOn(data.vLastDate, FALSE));
  161.         }
  162.         }
  163.         fclose(fd);
  164.     }
  165.     }
  166. }
  167.  
  168. /*
  169.  * crashout()
  170.  *
  171.  * Fatal error handler.
  172.  */
  173. void crashout(char *str)
  174. {
  175.     exit(printf("%s\n", str));
  176. }
  177.